#include "Channel.h"

// 实例化
Channel::Channel(int fd, FdEvent events, handleFunc readFunc, handleFunc writeFunc, handleFunc destroyFunc, void* arg)
	:_fd(fd), _events(static_cast<int>(events)), 
	_readCallback(readFunc), _writeCallback(writeFunc), _destroyCallback(destroyFunc), _arg(arg) {}

// 设置是否检测_fd的写事件
void Channel::writeEventEnable(bool flag) {
	if (flag) { _events |= static_cast<int>(FdEvent::_WriteEvent); }
	else { _events = _events & ~static_cast<int>(FdEvent::_WriteEvent); }
}

// 判断是否检测_fd的的写事件
bool Channel::isWriteEventEnable() const {
	return _events & static_cast<int>(FdEvent::_WriteEvent);
}

// 判断是否检测_fd的的读事件
bool Channel::isReadEventEnable() const {
	return _events & static_cast<int>(FdEvent::_ReadEvent);
}

// 对当前要检测的数据进行检测
void Channel::setCurrentEvent(FdEvent events) {
	_events = static_cast<int>(events);
}
